/**
 * Created by Administrator on 2017/4/13
 */
import React from "react";
import Relay from 'react-relay';
import { Icon,message } from 'antd';
import { hashHistory } from 'react-router';
import Util from "../../../util/Util";
import './css/OrderProgress.css';
import OrderProgressMutation from './mutation/OrderProgressMutation';

export default class OrderProgress extends React.Component{
  constructor(props) {
    super(props)
    this.state = {
      OrderProgressData: '',
      account: '',//订单金额
      payAccount: '', //已支付金额
      // orderId: this.props.location.query.oid,
      orderId: this.props.orderId,
      OrderProgress: '1', //状态展示
      enterpriseId: sessionStorage.getItem('enterpriseId'),
      receive: '',
      uid: sessionStorage.getItem('uid'),
      isLoading: true
    }
  }
  componentWillMount() {
    this.progress()
  }
  progress() {
    Relay.Store.commitUpdate(
        new OrderProgressMutation({
           msgType: 0,
           orderId: this.state.orderId,
           enId: this.state.enterpriseId
        }),
        {
            onFailure: () => {
                message.error('请求失败');
            },
            onSuccess: (response) => {
              let errorCode = response.queryMessagesByOrderId.queryMessagesByOrderId.errorCode
              if (errorCode == '0') {
                let OrderProgressData = response.queryMessagesByOrderId.queryMessagesByOrderId.messageAll
                this.setState({
                  OrderProgressData: OrderProgressData,
                  isLoading: false
                })
              } else {
                  message.error('请求失败');
                this.setState({
                  isLoading: false
                })
              }
            }
        }
    )
  }


  ClickDetail() {
    hashHistory.push('/sendGoodsRecord/'+ this.state.orderId)
  }
  percent() {
    let percent = parseInt( (this.state.payAccount/this.state.account)* 100)
    if (percent >= 100) {
      return 100
    } else {
      return percent
    }
  }

    _Supplement(actionStatus,v){
        if(actionStatus==8){
            this.refs.supplement.setState({
                visible:true,
                oid:v.orderId,
                inputaccount:v.money,
                textareadesp:v.addExplain,
                uid:v.userId
            });
        }
    }

  render() {
      return (
      <div className="progress_main">
        {
          //<img src={require("../img/order_banner.png")} alt="" />
        }
        <div>
          {
            this.state.isLoading ? <Icon type="loading" className="order_progress_loading"/> :(
                this.state.OrderProgressData && this.state.OrderProgressData.length >= 1 ? this.state.OrderProgressData.map((v, i) => {
                  return (
                    <div className="OrderProgress_content_flex">

                       <ul className='OrderProgress_content_ul'>

                            <p className="OrderProgress_content_status">{Util.dateFormat_hms(v.msgCreateDate)}</p>
                            <li>{ v.msgDetails}</li>
                       </ul>
                    </div>
                  )
              }) : (
                  <div className="OrderProgress_none">
                    该订单暂无进度
                  </div>
              )
            )
          }
        </div>

      </div>
    )
  }
}
